package com.test.demo.mongo;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class Usermongodbtest {

	@Autowired
	private UserRepository userRepository;
	
	
	public void getMongodata() {
		
		userRepository.deleteAll();
		userRepository.save(new User(1L, "kk", 18));
		userRepository.save(new User(2L, "jj", 18));
		userRepository.save(new User(3L, "bb", 18));
		System.out.println("mongodb存储的总数为："+userRepository.findAll().size());
		System.out.println("数据为："+userRepository.findAll());
		
		User u1=userRepository.findOne(1L);
		userRepository.delete(u1);
		System.out.println("删除一个之后，还存有的数目为："+userRepository.findAll().size());
		
		u1=userRepository.findByUsername("bb");
		userRepository.delete(u1);
		System.out.println("又删除一个，还存有的数目为："+userRepository.findAll().size());
		
		
		
		
			
	}
	
}
